package com.sscl.baselibrary.exts

import android.app.Activity
import android.content.Intent
import android.os.Build
import android.view.View
import android.view.WindowInsets

/**
 * 隐藏导航栏
 */
fun Activity.hideNavigationBar() {
    //隐藏导航栏
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        this.window.decorView.windowInsetsController?.hide(WindowInsets.Type.navigationBars())
    } else {
        val params = this.window.attributes
        @Suppress("DEPRECATION")
        params.systemUiVisibility =
            params.systemUiVisibility or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE
        this.window.attributes = params
    }
}

/**
 * 跳转到目标 意图 并结束当前Activity
 */
fun Activity.startActivityWithFinish(intent: Intent) {
    startActivity(intent)
    finish()
}

/**
 * 跳转到目标Activity并结束当前Activity
 */
fun <T : Activity> Activity.startActivityWithFinish(target: Class<T>) {
    startActivity(target)
    finish()
}